/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 牛孟俊
 * Date: 2023-11-16
 * Time: 17:43
 */

class Student {
    //私有属性
    private String name = "bit";
    //共有属性
    public int age = 18;
    //不带参数构造方法

    public Student() {
        System.out.println("Student()");
    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println("i am eat");
    }

    public void sleep() {
        System.out.println("i am pig");
    }
    private void function(String str) {
        System.out.println(str);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) throws ClassNotFoundException{
        //Class 对象只有一个，与对象的个数无关

        /*
    1.通过getClass()方法获取class对象
     */
        Student student = new Student();
        Class<?> c1 = student.getClass();//这就获取到了class对象
    /*
    2.类名.class
     */
        Class<?> c2 = Student.class;
    /*
    3.通过class.forName（静态方法）获取Class对象
     */
        Class<?> c3 = Class.forName("Student");
        //
        System.out.println(c1 == c2);
        System.out.println(c1 == c3);
        System.out.println(c3 == c2);
        //结果都为true
    }
}
